<?php

namespace App\Http\Controllers\admin;

use App\Dao\CategoryDao;
use App\Dao\GoodsDao;
use App\Services\Code;

class GoodsController extends BaseController
{
    public function goods()
    {
        if(getIsHasPage()){
            return  Code::message('',200,GoodsDao::pageinate(request()->all()));
        }
        return view('admin.goods.goods');
    }
    public function add()
    {
        if(isPost()){
            $params = request()->all();
            GoodsDao::add($params);
            return  Code::message();
        }
        $categorys = CategoryDao::get_datas();
        return view('admin.goods.add',[
            'categorys'=>$categorys
        ]);
    }
    public function edit()
    {
        if(isPost()){
            $params = request()->all();
            GoodsDao::update($params);
            return Code::message('',200);
        }
        $categorys = CategoryDao::get_datas();
        return view('admin.goods.edit',[
            'info'=>GoodsDao::goods_info(request()->all()),
            'categorys'=>$categorys
        ]);
    }

    public function del()
    {
        $params = request()->all();
        GoodsDao::delete($params);
        return Code::message('删除成功',200);
    }
}
